package com.app.toknow.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.app.toknow.R;

import java.util.Arrays;
import java.util.List;

/**
 * Created by kangw on 2015/10/5.
 */
public class SimpleSpinnerAdapter extends BaseAdapter {
    private TextView tvContent;
    private Context context;
    private LayoutInflater inflater;
    private List<String> data;
    public SimpleSpinnerAdapter(Context context,String[] strings)
    {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        data =  Arrays.asList(strings);
    }
    public SimpleSpinnerAdapter(Context context,List<String> list)
    {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        data = list;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        if(convertView == null)
            convertView = inflater.inflate(R.layout.spinner_text_layout, null);
        TextView label = (TextView) convertView.findViewById(android.R.id.text1);
        label.setText(data.get(position));
        return convertView;
    }

    @Override
    public View getDropDownView(int position, View convertView,ViewGroup parent) {
        if(convertView == null)
            convertView = inflater.inflate(R.layout.spinner_phone_area_item, null);
        TextView label = (TextView) convertView.findViewById(R.id.spinner_item_tv_phone_area);
        label.setText(data.get(position));
        return convertView;
    }
}
